package com.liser.southernstar.utils;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtils {

    /**
     * 获取异常堆栈信息
     */
    public static String getExceptionStack(Throwable ex){
        String msg;
        try{
            try( StringWriter sw = new StringWriter()){
                try(PrintWriter pw = new PrintWriter(sw)){
                    ex.printStackTrace(pw);
                    msg = new String(sw.toString().getBytes(), "UTF-8");
                }
            }
        }catch (Exception exIO){
            msg = "无法捕获的错误";
        }
        return msg;
    }
}
